
var orderId = '';  // 订单id
$(document).ready(function(){   
  orderId = '1111';
  getgoodsDetail();
  getEvaluationDeyail();
});

// 取消预约
$('#detailone').on('click','.cancelbutton',function(){
  removeGoodsDetail(2);
});

// 确认到店
$('#detailone').on('click','.confirmbutton',function(){
  removeGoodsDetail(5);
});

// 打开评价详情
$('#detailone').on('click','.view-evaluation',function(){
  $('.work-dialog').show();
});

// 关闭评价详情
$('.work-dialog').on('click','.header-title-right', function(){
  $('.work-dialog').hide();
});

// $('.work-dialog').click(function(e){
//   $('.work-dialog').hide();
// });

// 取消预约 
/**
 * @param  state  1: 待商家同意预约   2: 已取消  3: 商家同意预约
 * 4: 商家拒绝预约  5: 已完成（消费者确认到店）
 **/
function removeGoodsDetail(state){
  $.ajax({
    url: baseUrl+"/hsent-xxyl-user/orderDetailFree/modifyOrderFreeStatus",
    type:"get",	
    data:"orderId="+orderId+'&status='+state,	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){
        getgoodsDetail();
      }
    },
    error:function(res){
          
    },
  })
};

// 获取订单详情
function getgoodsDetail(){
  $.ajax({
    url: baseUrl+"/hsent-xxyl-user/orderDetailFree/findOrderDetailFreeByid",
    type:"get",	
    data:"orderId="+orderId,	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){
        res.data.entResno = res.data.entResno.substring(0,2)+' '+
        res.data.entResno.substring(2,5)+' '+
        res.data.entResno.substring(5,7)+' '+
        res.data.entResno.substring(7,11);
        res.data.applySerivceStaffs = JSON.parse(res.data.applySerivceStaffs);
        var data={
          data:res.data,
          pirUrl:pirUrl
        }
        console.log(data.data)
        var html = template('goods-detail-script', data);
				document.getElementById('detailone').innerHTML = html;
      }
    },
    error:function(res){
          
    },
  })
};

// 获取评价详情
function getEvaluationDeyail(){
  $.ajax({
    url: baseUrl+"/hsent-xxyl-user/evaluationRecord/findEvaluationByOrder",
    type:"get",	
    data:"orderId="+orderId,	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){
        var tempData = res.data;
        tempData.round = Math.round(tempData.evaluateValue);
        tempData.cha = 5 - tempData.round;
        var data={
          data:tempData,
          pirUrl:pirUrl
        }
        var html = template('work-dialog-script', data);
				document.getElementById('work-dialog-box').innerHTML = html;
      }
    },
    error:function(res){
          
    },
  })
}